#pragma once

#include <memory>
#include <thread>
#include <cmath>
#include <chrono>
#include <cassert>
#include "utils/utils.h"
#include "model/SubscriberNode.h"
#include "model/ClientNode.h"
#include "protocol/routeinfo.pb.h"
#include "protocol/transport.pb.h"
#include "base/Uri.h"
#include "base/Traits.h"
#include "base/Serializer.h"
#include "base/Message.h"
#include "base/Define.h"
#include "utils/utils.h"

namespace zeroplus::mq::consumer
{
    class ConsumerMediator;
    class MessageSubscriber
    {
    private:
        std::shared_ptr<ClientNode> client_;
        std::unique_ptr<SubscriberNode> subscriber_; // 推模式(发布订阅模式)
        std::shared_ptr<ConsumerMediator> mediator_;
        std::string topic_;

    public:
        MessageSubscriber(std::shared_ptr<ConsumerMediator> mediator);

        ~MessageSubscriber();

        transport::SubscribeMessageResponse SendSubscribeMessageRequest(const std::string &topic);

        void SendAckMessage(const std::string &messageId, const transport::ConsumeStatus &code);

        void ConnectToBroker(const std::string &uri);

        void SubscribeMessage(const std::string &topic);

        bool Listen(const std::function<void(const Bytes &)> OnListeningCb);
    };
}
